<template>
  <div class="page-login">
    <div class ='page-content' @keyup.enter='tryLogin_in'>
      <div class="login-modal">
        <div >
          <div class='l_username mb17'>
            <input  type='text' v-model='username'  v-el:username placeholder="Enter UserName"/>
          </div>
          <div class="l_password mb17">
            <input :type='type' v-model='password' v-el:password placeholder="Enter Password"/>
            <i @click='changePW'>click</i>
          </div>
          <div>
            <button @click='tryLogin_in' class='bg-color sing_up'>Login in </button>
          </div>
        </div>
        <div>
          <button @click='goSign_up' class='bg-color sing_up'>Create your Account</button>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
  import { login_in ,
    sign_up
  } from '../vuex/actions'
  import { getCurrentUser } from '../vuex/getters'
  export default{
    vuex:{
      actions:{
        login_in,
        sign_up
      },
      getters:{
        getCurrentUser,
      }
    },
    data(){
      return{
        type:"password",
        phonePage:true,
        username:'',
        password:''
      }
    },
    components:{
    },
    methods:{
      changePW(){
        this.type = this.type == 'password' ? "text" : "password"
      },
      tryLogin_in(){
        const username = this.username
        const password = this.password
        const user = {
          username : username,
          password : password
        }
        this.login_in(user)
        if(this.getCurrentUser.privilege){
          this.$route.router.go('/main/home')
        }else{
          alert("用户密码不正确,请重新输入")
        }
      },
      goSign_up(){
        this.$router.go('/Login')
      }
    },
    computed:{
      phone_class(){
        return this.phonePage ? 'bg-color focus' : 'bg-color'
      },
      email_class(){
        return this.phonePage ? 'bg-color' : 'bg-color focus'
      }
    },
    ready(){
      var el = this.$els.username
      setTimeout(()=>{
        el.focus()
      },16)
    }
  }
</script>
<style scoped>
  input{
    appearance:none;
    outline: none;
    width:452px;
    height:40px;
    line-height:40px;
    display: inline-block;
    margin-bottom: 1rem;
    color: rgba(255, 255, 255, 0.7);
    background-color: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.2);
    border-style: solid;
    border-width: 1px;
    /*border-radius: 0.3rem;*/
    transition: color 0.2s, background-color 0.2s, border-color 0.2s;
    padding:0 10px;
  }
  input:hover{
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    background-color: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
  }
  button{
    width:50%;
    height:40px;
    appearance:none;
    -webkit-appearance:none
  }
  button.sing_up{
    width: 452px;
  }
  .bg-color{
    line-height:40px;
    display: inline-block;
    outline: none;
    margin-bottom: 1rem;
    color: rgba(255, 255, 255, 0.7);
    background-color: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.2);
    border-style: solid;
    border-width: 1px;
    /*border-radius: 0.3rem;*/
    transition: color 0.2s, background-color 0.2s, border-color 0.2s;
  }
  .bg-color:hover{
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    background-color: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
  }
  .bg-color.focus{
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    background-color: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
  }
  .page-login{
    background-color: #159957;
    background-image: linear-gradient(120deg, #155799, #159957);
    display: flex;
    justify-content: center;
    padding: 150px 0 261px 0;
  }
  .page-content{
    font-size:16px;
    height:100%;
    width:452px;
    color: #ffffff;
    /*text-align: center;*/
    /*display:flex;*/
    /*justify-content: space-between;*/
    /*align-items: flex-start;*/
  }
  .login-modal{

  }
  .fl{
    float: left;
  }
  .l_username{

  }
  .l_password{
    position: relative;
  }
  .l_password i{
    position: absolute;
    right:0;
    top:8px;
  }
  .mb17{
    margin-bottom: 17px;
  }
  .display_none{
    display:none;
  }
  .display_block{
    display:block;
  }
</style>
